package com.ht.modules.system.controller;

import com.ht.entity.Result;
import com.ht.aspect.annotation.AutoLog;
import com.ht.modules.system.entity.SysLoginError;
import com.ht.modules.system.entity.SysLoginErrorVo;
import com.ht.modules.system.service.ISysLoginErrorService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 *  登录错误表
 * @Author:
 * @Date:   2021-06-21
 * @Version: V1.0
 */
@Slf4j
@Api(tags="登录错误表")
@RestController
@RequestMapping("/system/sysLoginError")
public class SysLoginErrorController {

	@Autowired
	private ISysLoginErrorService sysLoginErrorService;

	/**
	 * 分页列表查询
	 * @param sysLoginErrorVo
	 * @param pageNo 页码
	 * @param pageSize 当页大小
	 * @return
	 */
	@ApiOperation(value="登录错误表-分页列表查询", notes="登录错误表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<SysLoginErrorVo>> queryPageList(SysLoginErrorVo sysLoginErrorVo,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
		Result<IPage<SysLoginErrorVo>> result = new Result<>();
		Page<SysLoginErrorVo> page = new Page<>(pageNo, pageSize);
		page = sysLoginErrorService.list(page, sysLoginErrorVo);
		result.success("查询成功！");
		result.setResult(page);
		return result;
	}

	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	@ApiOperation(value="登录错误表-通过id查询", notes="登录错误表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<SysLoginError> queryById(@RequestParam(name="id") String id) {
		Result<SysLoginError> result = new Result<>();
		try {
            SysLoginError sysLoginError = sysLoginErrorService.queryById(id);
            result.setResult(sysLoginError);
            result.success("查询成功！");
        } catch (Exception e) {
            result.error500("操作失败！" + e.getMessage());
        }
		return result;
	}

     /**
      * 批量解封
      * @param ids 需要解封的ids
      * @param unsealReason 解封原因
      * @return
      */
     @AutoLog(value = "登录错误表-批量解封")
     @ApiOperation(value="登录错误表-批量解封", notes="登录错误表-批量解封")
     @PutMapping(value = "/unsealBatch")
     public Result<?> unsealBatch(@RequestParam(name="ids") String ids,
                                  @RequestParam(name="unsealReason") String unsealReason) {
         Result<?> result = new Result<>();
         try {
             sysLoginErrorService.unsealBatch(ids, unsealReason);
             result.success("解封成功！");
         } catch (Exception e){
             log.error(e.getMessage(),e);
             result.error500("解封失败！" + e.getMessage());
         }
         return result;
     }

}
